package com.aso114.project.dialog;

import android.content.Context;

/**
 * 作者： Mr.H on 2017/6/13 0013
 * 邮箱：2881032622@qq.com
 * CLASS：自定义进度条
 */

public class ProgressDialogUtil {

    /**
     * dialog 进度条
     */
    private static MyProgressDialog dialog;

    /**
     * @param context
     * @param message   提示内容
     * @param canCancel 是否能取消
     */
    public static void show(Context context, String message, boolean canCancel) {
        if (null == dialog) {
            initProgressDialog(context, message, canCancel);
        } else if (dialog.getContext() != context) {
            cancel();
            initProgressDialog(context, message, canCancel);
        }
        if (!dialog.isShowing())
            dialog.show();
    }

    /**
     * @param context 初始化进度条
     * @param message
     */
    private static void initProgressDialog(Context context, String message, boolean canCancel) {
        dialog = new MyProgressDialog(context, message, canCancel);
        dialog.setCanceledOnTouchOutside(false);//设置在点击Dialog外是否取消Dialog进度条
    }

    /**
     * 取消进度条
     */
    public static void cancel() {
        if (null == dialog) {
            return;
        } else {
            if (dialog.isShowing()) {
                dialog.dismiss();
                dialog = null;
            }
        }
    }

    /**
     * @return 进度条是否已显示
     */
    public static boolean isShow() {
        return (null != dialog && dialog.isShowing());
    }

}
